<template>
	<view class="content">
		<view class="category-title-list">
			<scroll-view class="category-title-box" scroll-x="true">
				<view @click="selectCategory(index)" v-for="(item, index) in category" class="category-title-item" :key="index" :class="item.active ? 'active':''">{{item.name}}</view>
			</scroll-view>
			<view class="category-search">
				<navigator url="/pages/workorder/search?type=category" class="category-search-box" hover-class="category-search-hover">
					<icon class="category-search-icon" type="search" size="18"/>
				</navigator>
			</view>
		</view>
		<view class="category-list">
			<block v-for="(item, index) in category" :key="index">
				<block v-if="item.active">
					<navigator :url="'/pages/workorder/kbs?id=' + childItem.id" v-for="(childItem, idx) in item.child" :key="idx" class="category-item">
						<image class="category-logo" :src="childItem.logo_image"></image>
						<view class="category-info">
							<view class="category-title">{{childItem.name}}</view>
							<view class="category-introduce">{{childItem.desc}}</view>
						</view>
					</navigator>
				</block>
			</block>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				category: []
			}
		},
		onLoad() {
			this.$u.api.category().then(res => {
				for (let c in res.data.category) {
					res.data.category[c].active = false
				}
				res.data.category[0].active = true
				this.category = res.data.category
			})
		},
		methods: {
			selectCategory: function (index) {
				for (let c in this.category) {
					this.category[c].active = false
				}
				this.category[index].active = true
			}
		}
	}
</script>

<style>
.category-title-list {
	position: fixed;
	height: 100rpx;
	width: 100vw;
	background: #FFFFFF;
}
.category-title-box {
	white-space: nowrap;
	padding-left: 30rpx;
	padding-right: 90rpx;
	box-sizing: border-box;
}
.category-title-item {
	display: inline-block;
	padding: 26rpx 20rpx;
	margin: 0 10rpx;
	font-size: 30rpx;
	line-height: 46rpx;
	text-align: center;
	border-bottom: 1px solid #EBEBEB;
}
.category-search {
	position: relative;
}
.category-search-box {
	position: absolute;
	height: 100rpx;
	width: 100rpx;
	bottom: 0rpx;
	right: 0;
	background: #FFFFFF;
	display: flex;
	align-items: center;
	justify-content: center;
}
.category-search-hover {
	background: #EBEBEB;
}
.category-title-item.active {
	border-bottom: 1px solid #007AFF;
}
.category-list {
	padding-top: 100rpx;
}
.category-item {
	display: flex;
	align-items: center;
	padding: 20rpx 30rpx;
}
.category-logo {
	width: 120rpx;
	height: 120rpx;
	min-width: 120rpx;
	min-height: 120rpx;
	padding-right: 20rpx;
}
.category-title {
	font-size: 30rpx;
	font-weight: bold;
}
.category-introduce {
	font-size: 28rpx;
	color: #888;
}
</style>
